#include "Node/LRG_Node_ActorListFrequencyBuckets.h"

bool ULRG_Node_ActorListFrequencyBuckets::NotifyRemoveNetworkActor(const FNewReplicatedActorInfo& ActorInfo, bool bWarnIfNotFound)
{
	bool bRemovedSomething = false;
	if (ActorInfo.StreamingLevelName == NAME_None)
	{
		bool bFound = false;
		for (FActorRepListRefView& List : NonStreamingCollection)
		{
			if (List.RemoveSlow(ActorInfo.Actor))
			{
				bRemovedSomething = true;
				TotalNumNonStreamingActors--;
				CheckRebalance();

				//if (!CVar_RepGraph_Verify)
				{
					// Eary out if we dont have to verify
					return bRemovedSomething;
				}

				if (bFound)
				{
					// We already removed this actor so this is a dupe!
					//repCheck(CVar_RepGraph_Verify);
					ensureMsgf(false, TEXT("Actor %s is still in %s after removal"), *ActorInfo.Actor->GetDesc(), *GetDesc() );
				}

				bFound = true;
			}
		}

		if (!bFound && bWarnIfNotFound)
		{
			UE_LOG(LogReplicationGraph, Warning, TEXT("Attempted to remove %s from list %s but it was not found. (StreamingLevelName == NAME_None)"), *ActorInfo.Actor->GetDesc(), *GetDesc());
		}
	}
	else
	{
		bRemovedSomething = StreamingLevelCollection.RemoveActor(ActorInfo, bWarnIfNotFound, this);
	}

	return bRemovedSomething;
}


void ULRG_Node_ActorListFrequencyBuckets::NotifyAddNetworkActor(const FNewReplicatedActorInfo& ActorInfo)
{
	Super::NotifyAddNetworkActor(ActorInfo);
}

void ULRG_Node_ActorListFrequencyBuckets::SetCoordinate(const FSpatialCoordinate& InCoordinate)
{
	Coordinate.X = InCoordinate.X;
	Coordinate.Y = InCoordinate.Y;
	Describe.Empty();
}

FString ULRG_Node_ActorListFrequencyBuckets::GetDesc()
{
	if(Describe.IsEmpty())
	{
		Describe = FString::Printf(TEXT("GActorListNode_%d_%d"), Coordinate.Y, Coordinate.Y);
	}
	return Describe;
}
